package com.lzx.java.smack.concurrent;

import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {

	public static void main(String[] args) throws InterruptedException {

		Callable<String> callable = new Callable<String>() {

			@Override
			public String call() throws Exception {
//				System.in.read();
				
				Thread.sleep(10000L);
				System.out.println("finished...");
				
				
			
				
			
				return "finished";
			}
		};

		ExecutorService executorService = Executors.newFixedThreadPool(5);

		try {
			Future<String> future = executorService.submit(callable);
			System.out.println("isCancelled:" + future.isCancelled());
			System.out.println("isDone:" + future.isDone());
			
			Thread.sleep(500);
			
			System.out.println(future);
			System.out.println("cancel:" + future.cancel(false));
			
			
			
			System.out.println("isCancelled:" + future.isCancelled());
			System.out.println("isDone:" + future.isDone());
			
//			System.out.println("get:" + future.get());
			
		} catch (Exception e) {
			e.printStackTrace();
		}

		executorService.shutdownNow();

	}

}
